<template>
  <div>
    <div id="slider"
         class="mui-slider">
      <div id="sliderSegmentedControl"
           class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
        <div class="mui-scroll">
          <a :class="['mui-control-item', item.id ==0 ? 'mui-active' : '']"
             data-wid="tab-top-subpage-1.html"
             v-for="(item, index) in cates"
             :key="index"
             @tap="getPhotoListByCateId(item.id)">
            {{item.title}}
          </a>
        </div>
      </div>

    </div>

    <ul class="photo-list">
      <router-link v-for="(item, index) in list"
                   :key="index"
                   :to="'/home/photoinfo/' + item.id"
                   tag="li">
        <img v-lazy="item.img_url">
        <div class="info">
          <h2 class="info-title">{{item.title}}</h2>
          <div class="info-boby">{{item.summary}}</div>
        </div>
      </router-link>
    </ul>
  </div>
</template>

<script>
import mui from '../../lib/mui/js/mui.min.js';

export default {
  data() {
    return {
      cates: [],
      list: []
    }
  },
  created() {
    this.getAllCategory();
    this.getPhotoListByCateId();
  },
  mounted() {
    mui('.mui-scroll-wrapper').scroll({
      deceleration: 0.0005
    });
  },
  methods: {
    getAllCategory() {
      this.axios.get('/getimgcategory').then(res => {
        this.cates = res.data;
      })
    },
    getPhotoListByCateId(cateId = 0) {
      let myurl = cateId == 0 ? '/getimages' : `/getimages?cateId=${cateId}`;
      this.axios.get(myurl).then(res => {
        this.list = res.data;
      })
    }
  }
}
</script>

<style lang="scss" scoped>
* {
  touch-action: pan-y;
}

.photo-list {
  list-style: none;
  padding: 10px;
  margin: 0;
  padding-bottom: 0;
  li {
    margin-bottom: 10px;
    background-color: #eee;
    text-align: center;
    box-shadow: 0 0 9px #999;
    position: relative;
    img {
      width: 100%;
      height: 400px;
      vertical-align: middle;
    }
    img[lazy="loading"] {
      width: 40px;
      height: 300px;
      margin: auto;
    }
    .info {
      color: #fff;
      text-align: left;
      position: absolute;
      bottom: 0;
      background-color: rgba(0, 0, 0, 0.4);
      .info-title {
        font-size: 15px;
      }
      .info-boby {
        font-size: 13px;
      }
    }
  }
}
</style>